package org.example;

import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class CMController {
    @Resource
    RestTemplate restTemplate;
    @Resource
    DiscoveryClient discoveryClient;
    /**
     * 使用服务名调用
     */
    String url2 = "http://serv";

    @GetMapping("b")
    public String bb() {
        List<ServiceInstance> serv = discoveryClient.getInstances("serv");
        serv.forEach(System.out::println);
        return restTemplate.getForObject(url2 + "/b", String.class);
    }
}